
# 文件的打开
"""
- 打开文件
- 读写文件
- 关闭文件
"""
# f = open('test.txt','r', encoding='utf-8')
# print(f, type(f))
# 读取文件
# print(f.read(11))
# 多次调用read，会从上一次读取的位置开始
# print(f.read())

# print(f.readlines())
# print(f.readline(), end='')
# print(f.readline(), end='')
# print(f.readline(), end='')

# for line in f:
#     print(line)
#
# f.close()

# 语法糖，可以自动执行f.close关闭方法
# with open('test.txt','r', encoding='utf-8') as f:
#     for line in f:
#         print('======', line)
#
# l = [2,3,4,2,3]
# print(l.count(2))

# 写入会直接覆盖
# with open('music.txt','w', encoding='utf-8') as f:
#     f.write('以父之名')
#     f.flush()
# f.close()自带有flush功能

# 追加内容
with open('music.txt','a', encoding='utf-8') as f:
    f.write('\n止战之殇')
    f.flush()

with open('music.txt','r', encoding='utf-8') as f:
    print(f.read())